﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SD.IBUS;
using SD.Entities;
using SD.IDAL;
using SD.DAL;
using System.Data;
using System.Data.SqlClient;

namespace SD.BUS
{
    public class DirectorateBIZ : BaseBIZ, IDirectorateBIZ
    {
        #region IDirectorateBIZ Members

        IDirectorateDAO directorateDAO= new DirectorateDAO();
        /// <summary>
        /// Get all Directorate add into list Directorate
        /// </summary>
        /// <param name="filterExpression"></param>
        /// <param name="includeInactive"></param>
        /// <returns>list Directorate</returns>
        public DataTable GetAll(string filterExpression, bool includeInactive)
        {
            DataTable dtbResult = new DataTable();
            dtbResult.Columns.Add("DirectorateID");
            dtbResult.Columns.Add("Name");
            dtbResult.Columns.Add("Line1");
            dtbResult.Columns.Add("Postcode");
            dtbResult.Columns.Add("Surname");
            dtbResult.Columns.Add("IsActive");

            try
            {
                List<Directorate> lstDrect = directorateDAO.GetAll(filterExpression, includeInactive);

                if (lstDrect.Count > 0)
                {
                    foreach (Directorate drect in lstDrect)
                    {
                        dtbResult.Rows.Add(drect.DirectorateId, drect.Name,
                                            drect.Address != null ? drect.Address.Line1 : "N/A",
                                            drect.Address != null ? drect.Address.PostCode : "N/A",
                                            drect.Contact != null ? drect.Contact.FirstName : "N/A",
                                            drect.IsActive);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return dtbResult;
        }
        public DataTable GetAllFilter(bool includeInactive)
        {
            DataTable dtbResult = new DataTable();
            dtbResult.Columns.Add("DirectorateID");
            dtbResult.Columns.Add("Name");
            dtbResult.Columns.Add("Line1");
            dtbResult.Columns.Add("Postcode");
            dtbResult.Columns.Add("Surname");
            dtbResult.Columns.Add("IsActive");

            try
            {
                List<Directorate> lstDrect = directorateDAO.GetAllFilter(includeInactive);
                if (lstDrect.Count > 0)
                {
                    foreach (Directorate drect in lstDrect)
                    {
                        dtbResult.Rows.Add(drect.DirectorateId, drect.Name,
                                            drect.Address != null ? drect.Address.Line1 : "N/A",
                                            drect.Address != null ? drect.Address.PostCode : "N/A",
                                            drect.Contact != null ? drect.Contact.FirstName : "N/A",
                                            drect.IsActive);
                    }
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return dtbResult;
        }

        #endregion
    }
}
